package net.zoneland.knowledge.model;

import java.io.Serializable;

public class ResponseResultRest implements Serializable {
    private static final long serialVersionUID = 1L;

    private boolean success;

    private String message;

    private Object data;

    private int dataLength;

    private static final String SUCCESS_DEFAULT_CODE = "200";

    private static final String SUCCESS_DEFAULT_MSG = "执行成功";

    private static final String FAILURE_DEFAULT_MSG = "执行失败";

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String toString() {
        return "ResponseResultRest(success=" + isSuccess() + ", message=" + getMessage() + ", data=" + getData() + ", length=" + getDataLength() + ")";
    }

    public ResponseResultRest(boolean success, String message, Object data, int dataLength) {
        this.success = success;
        this.message = message;
        this.data = data;
        this.dataLength = dataLength;
    }

    public ResponseResultRest() {
    }

    public boolean isSuccess() {
        return this.success;
    }

    public String getMessage() {
        return this.message;
    }

    public Object getData() {
        return this.data;
    }

    public int getDataLength() {
        return dataLength;
    }

    public static ResponseResultRest success() {
        return builder().success(true).message(SUCCESS_DEFAULT_MSG).build();
    }

    public static ResponseResultRest success(Object data) {
        return builder().success(true).message(SUCCESS_DEFAULT_MSG).data(data).build();
    }

    public static ResponseResultRest success(Object data, int dataLength) {
        return builder().success(true).message(SUCCESS_DEFAULT_MSG).data(data, dataLength).build();
    }

    public static ResponseResultRest failure() {
        return builder().success(false).message(FAILURE_DEFAULT_MSG).build();
    }

    public static ResponseResultRest failure(String message) {
        return builder().success(false).message(message).build();
    }

    public static ResponseResultBuilder builder() {
        return new ResponseResultBuilder();
    }

    public static class ResponseResultBuilder {
        private boolean success;

        private String message;

        private Object data;

        private int dataLength;

        public ResponseResultRest build() {
            return new ResponseResultRest(this.success, this.message, this.data, this.dataLength);
        }

        public ResponseResultBuilder success(boolean success) {
            this.success = success;
            return this;
        }

        public ResponseResultBuilder message(String message) {
            this.message = message;
            return this;
        }

        public ResponseResultBuilder data(Object data) {
            this.data = data;
            return this;
        }

        public ResponseResultBuilder data(Object data, int length) {
            this.data = data;
            this.dataLength = length;
            return this;
        }

        public String toString() {
            return "ResponseResult.ResponseResultBuilder(success=" + this.success + ", message=" + this.message + ", data=" + this.data + ", length=" + this.dataLength + ")";
        }
    }
}
